package zr;

import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.net.UnknownHostException;

import javax.swing.JButton;
import javax.swing.JFrame;

import zr.component.ServerSearchDialog;
import zr.util.Logger;

public class Welcome {

	private final static org.apache.log4j.Logger logger = Logger
			.getInstance(Welcome.class);
	static JFrame f = new JFrame("Welcome!");
	static JButton join = new JButton("加入游戏");
	static JButton neww = new JButton("新建游戏");

	public static void main(String[] args) {
		// 这是打酱油的注释，我用来测试提交代码是否需要使用账号。
		// 因为忘了勾选记住账号，我不得不又加入一句注释...
		f.setLayout(new GridLayout(2, 1, 2, 2));
		f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

		f.add(neww);
		f.add(join);
		int width = 200, height = 100;
		Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
		f.setSize(width, height);
		f.setLocation((int) (screenSize.getWidth() - width) / 2,
				(int) (screenSize.getHeight() - height) / 2);
		f.setResizable(false);
		f.setVisible(true);
		addListeners();
	}

	private static void addListeners() {
		neww.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				logger.info("新建游戏");
				Main.server();
				f.dispose();
				Main.start();
			}
		});
		join.addActionListener(new ActionListener(){
			@Override
			public void actionPerformed(ActionEvent e) {
				f.dispose();
				try {
					ServerSearchDialog ssd=new ServerSearchDialog();
				} catch (UnknownHostException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}
			}			
		});
	}
}
